package de.lmu.ifi.dbs.trafficmining.simplex;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jdesktop.swingx.JXPanel;

public class SimplexControl1D<T extends PointPanel.PointSource> extends JXPanel implements SimplexControl<T> {

    public SimplexControl1D() {
        initComponents();
    }

    @Override
    public void setPoints(Collection<T> ps) {
        pointPanel.setPoints(ps);
    }

    @Override
    public void setHighlight(Collection<T> ps) {
        pointPanel.setHighlight(ps);
    }

    @Override
    public void setAttributNames(List<String> names) {
        if (names == null || names.size() <= 0) {
            return;
        }
        attributeLabel.setText(names.get(0));
    }

    @Override
    public PointPanel getPointPanel() {
        return pointPanel;
    }

    @Override
    public T getSourceFor(T eventSource) {
        if (pointPanel.getPoints().contains(eventSource)) {
            return eventSource;
        } else {
            return null;
        }
    }

    @Override
    public List<T> getSourceFor(List<T> eventSource) {
        List<T> out = new ArrayList<>();
        for (T in : eventSource) {
            T p = getSourceFor(in);
            if (p != null) {
                out.add(p);
            }
        }
        return out;
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        pointPanel = new de.lmu.ifi.dbs.trafficmining.simplex.PointPanel();
        minLabel = new javax.swing.JLabel();
        maxLabel = new javax.swing.JLabel();
        attributeLabel = new javax.swing.JLabel();

        setLayout(new java.awt.GridBagLayout());

        pointPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        javax.swing.GroupLayout pointPanelLayout = new javax.swing.GroupLayout(pointPanel);
        pointPanel.setLayout(pointPanelLayout);
        pointPanelLayout.setHorizontalGroup(
            pointPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 363, Short.MAX_VALUE)
        );
        pointPanelLayout.setVerticalGroup(
            pointPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 11, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(pointPanel, gridBagConstraints);

        minLabel.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        add(minLabel, gridBagConstraints);

        maxLabel.setText("max");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.3;
        add(maxLabel, gridBagConstraints);

        attributeLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        attributeLabel.setText("Attribute value");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.3;
        add(attributeLabel, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel attributeLabel;
    private javax.swing.JLabel maxLabel;
    private javax.swing.JLabel minLabel;
    private de.lmu.ifi.dbs.trafficmining.simplex.PointPanel pointPanel;
    // End of variables declaration//GEN-END:variables
}
